<!-- 提醒中心 -->
<template>
  <div>
      <div class="searchbox">
        <el-form :inline="true" size="small" label-width="100px">
          <el-form-item label="任务单号">
            <el-input size="small" v-model="form.taskNo" placeholder="任务单号"></el-input>
          </el-form-item>
          <!--<el-form-item label="提醒人">
            <el-input size="small" v-model="form.noticeUser" placeholder="提醒人"></el-input>
          </el-form-item>-->
          <el-form-item label="委托日期:">
            <el-date-picker size="small" value-format="yyyy-MM-dd HH:mm:ss" :default-time="['00:00:00', '23:59:59']" v-model="form.date" type="daterange" range-separator="至" start-placeholder="开始日期" end-placeholder="结束日期"
              style="width: 220px">
            </el-date-picker>
          </el-form-item>
          <el-form-item style="margin-left: 20px;">
            <el-button size="mini" type="primary" @click="showList">查询</el-button>
          </el-form-item>
          <el-form-item>
            <el-button size="mini" @click='clearForm'>清除</el-button>
          </el-form-item>
        </el-form>
      </div>

      <div class="contentbox">
        <div style="float: left;padding-left: 20px;font-size: 15px;color: #666;padding-top: 6px;">
          提醒中心信息 共 <span style="color: red;">{{pageTotal}}</span> 条数据
        </div>
        <el-row style="float: right;margin-right: 20px;margin-bottom: 15px;" type="flex" justify="end">
          <el-col>
            <jt-table-column-filter tableName='remindCenter' :table-key.sync="tableKey" :header-data.sync="tableHeaderArr" :filter-column.sync="filterColumnData"></jt-table-column-filter>
            <check-entrust-report :show.sync="isShowAuditReport" :detailId='taskId'  @refreshAdd="showList"></check-entrust-report>
            <upload-entrust-report :show.sync="isShowEntrustReport" :detailId="detailId"  @refreshAdd="showList"></upload-entrust-report>
          </el-col>
        </el-row>
        <!-- 表格 -->
        <el-table :data="tableData" :key='tableKey' v-loading="loading" stripe>
          <el-table-column :index="indexMethod" type="index" label="序号" width="50" align="center" :resizable="false"></el-table-column>
          <el-table-column align="center" :key='item' v-for='item in filterColumnData' :resizable="false"
              :label="getTableHeaderLabel(item)"
              :prop="item"
              :min-width="getTableColumnWidth(item)"
              :fixed="getTableColumnFixed(item)"
              :sortable="getTableColumnSort(item)">
              <template slot-scope="scope">
                <span v-if="item == 'noticeStartUser'">{{scope.row[item].name}}</span>
                <span v-else>{{scope.row[item]}}</span>
                <el-button v-if="item === 'operate' && scope.row['taskStatus'] =='1'" size="small" type="text" @click="acceptSample(scope.row)">接收样品</el-button>
                <el-button v-if="item === 'operate' && scope.row['taskStatus'] =='5'" size="small" type="text" @click="acceptTask(scope.row)">接受任务</el-button>
                <el-button v-if="item === 'operate' && scope.row['taskStatus'] =='4'" size="small" type="text" @click="recordDta(scope.row)">录入数据</el-button>
                <el-button v-if="item === 'operate' && scope.row['taskStatus'] =='6'" size="small" type="text" @click="auditOrder(scope.row)">审核</el-button>
                <el-button v-if="item === 'operate' && scope.row['taskStatus'] =='7'" size="small" type="text" @click="auditOrder(scope.row)">二次审核</el-button>
              </template>
          </el-table-column>
        </el-table>
        <el-row type="flex" justify="center">
          <el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange" :current-page="currentPage" :page-sizes="pageSizeArr"
            :page-size="pageSize" layout="total, sizes, prev, pager, next, jumper" :total="pageTotal"></el-pagination>
        </el-row>
    </div>
  </div>
</template>

<script>
  import JtTableColumnFilter from 'components/jt-table-column-filter/index'; // 导入表格列筛选组件
  import { 
            getMyTodo,
            getMyNotice,
           postBatchTakeSampleService,
           postTakeTaskService
          } from 'service/task';
          
  import CheckEntrustReport from 'dialog/experimental-management/experimental-report-generation/inspection-data-audit/check-entrust-report';
  import UploadEntrustReport from 'dialog/experimental-management/experimental-report-generation/data-uploading/upload-entrust-report';
    import { getLableFromList } from 'utils/common';
  import {
    APPLY_STATUS_LIST
  } from 'service/constant'
  export default {
    name: 'RemindingCenter',
    components: {
      'jt-table-column-filter': JtTableColumnFilter,
      'check-entrust-report': CheckEntrustReport,
      'upload-entrust-report': UploadEntrustReport
    },
    data() {
      return {
        tableKey: 1, // table key
        filterColumnData: [],
         taskStatusList:APPLY_STATUS_LIST,

        tableHeaderArr: [{
              'name': 'noticeTime',
              'alias': '提醒时间',
              'default': true,
              'width': 100,
              'fixed': false,
              'sort': true
          },
          {
              'name': 'applyTime',
              'alias': '委托时间',
              'default': true,
              'width': 100,
              'fixed': false,
              'sort': true
          },
          {
              'name': 'taskNo',
              'alias': '任务单号',
              'default': true,
              'width': 100,
              'fixed': false,
              'sort': true
          },
           {
              'name': 'partNumber',
              'alias': '零件号',
              'default': true,
              'width': 80,
              'fixed': false,
              'sort': true
          },
          {
              'name': 'partName',
              'alias': '零件名称',
              'default': true,
              'width': 80,
              'fixed': false,
              'sort': true
          },
          {
              'name': 'heatingNumber',
              'alias': '热处理炉号',
              'default': true,
              'width': 80,
              'fixed': false,
              'sort': true
          },
           {
              'name': 'taskStatusStr',
              'alias': '任务单状态',
              'default': true,
              'width': 80,
              'fixed': false,
              'sort': true
          },
          {
              'name': 'content',
              'alias': '提醒内容',
              'default': true,
              'width': 80,
              'fixed': false,
              'sort': true
          }
        //   ,{
        //   'name': "operate",
        //   'alias': "操作",
        //   'default': true,
        //   'width': 50,
        //   'fixed': "right",
        //   'sort': false
        // }
        ],
        tableData: [],
        loading: false,
        isShowAuditReport:false,
        isShowEntrustReport:false,
        taskId: '',
        detailId: '',
        form: {
          taskNo: '',
          noticeUser: '',
          date: ''
        },
        currentPage: 1,
        pageSizeArr: [10, 20, 50, 100],
        pageSize: 10,
        pageTotal: 10
      }
    },
    mounted() {
      this.showList();
    },
    methods: {
      indexMethod(index) {
        return index + this.pageSize * (this.currentPage-1) + 1;
      },
      clearForm(){
        this.form={};
        this.showList();
      },
      handleSizeChange(val) {
        this.pageSize = val;
        this.showList();
      },
      handleCurrentChange(val) {
        this.currentPage = val;
        this.showList();
      },
      // 审核
      auditOrder(row) {
        getMyTodo(row.taskNo, row.taskStatus, '', '', this.currentPage, this.pageSize, '', '').then(res1 => {
          this.taskId  =res1.data.result.content[0].id;
          this.isShowAuditReport = true;
        });
      },
       recordDta(row) {
        getMyTodo(row.taskNo, row.taskStatus, '', '', this.currentPage, this.pageSize, '', '').then(res1 => {
          this.detailId =res1.data.result.content[0].id;
          this.isShowEntrustReport = true;
        });
      },
      acceptSample(row) {
        this.$confirm('是否接收此样品?', '提示', {
          type: 'warning'
        }).then(() => {
          let submitForm = {};
          let newArr = [];
          newArr.push(row.taskNo);
          submitForm.taskNo = newArr;
          postBatchTakeSampleService(submitForm)
            .then(res => {
              if (res.data.success) {
                this.$message({
            message: `已接收的样品对应任务单号为：${row.taskNo}`,
            type: 'success',
            duration: 1000
            });
                this.showList();
              } else {
                this.$alert(res.data.message, '提示', {
                  type: 'error'
                })
              }
            })
        }).catch(() => {});
      },
      // 任务领取
      acceptTask(row) {
        this.$confirm('是否接取此任务单?', '提示', {
          type: 'warning'
        }).then(() => {
          getMyTodo(row.taskNo, row.taskStatus, '', '', this.currentPage, this.pageSize, '', '')
          .then(res1 => {
            postTakeTaskService(res1.data.result.content[0].id)
            .then(res => {
              if (res.data.success) {
                 this.$message({
            message: `已接取的任务单号为：${row.taskNo}`,
            type: 'success',
            duration: 1000
            });
                this.showList();
              } else {
                this.$alert(res.data.message, '提示', {
                  type: 'error'
                })
              }
            })
          })
         
        }).catch(() => {});
      },
      // 表格数据展示
      showList() {
        let startDate = '';
        let endDate = '';
        if(this.form.date != '') {
          startDate = this.form.date[0];
          endDate = this.form.date[1];
        }
        this.loading = true;
        // this.axios.get('/task/applyList')
        const data = {
          'taskNo': this.form.taskNo,
          'taskStatus':  this.form.startUserId,
          'applyStart': startDate,
          'applyEnd': endDate,
          'pageNumber': this.currentPage,
          'pageSize':  this.pageSize,
          'sort': '',
          'order': ''
        }//this.form.taskNo, this.form.startUserId, startDate, endDate, this.currentPage, this.pageSize, '', ''
        getMyNotice(data)
          .then(res => {
            // console.log(res)
            this.tableData = res.data.result.content;
            
            this.tableData.forEach(e => {
                if(e.noticeTime!=null && e.noticeTime!='' && e.noticeTime!=' '){
                  var dateee = new Date(e.noticeTime).toJSON();
                  dateee =new Date(+new Date(dateee) + 8 * 3600 * 1000).toISOString().replace(/T/g, ' ').replace(/\.[\d]{3}Z/, '');
                  e.noticeTime = dateee;
                };
            });
            // this.currentPage = res.data.result.pageable.pageNumber;
            this.pageSize = res.data.result.pageable.pageSize;
            this.pageTotal = res.data.result.totalElements;
             this.tableData.forEach(e => {
              e.taskStatusStr = getLableFromList(APPLY_STATUS_LIST, e.taskStatus);
            })
            this.loading = false;
          })
      },
      // 表头展示
      getTableHeaderLabel(str) {
        return this.getTableSomeValue(str, 'alias');
      },
      // 获取表格列的宽度
      getTableColumnWidth(str){
        return this.getTableSomeValue(str, 'width');
      },
      // 获取表格列是否是固定的
      getTableColumnFixed(str){
        return this.getTableSomeValue(str, 'fixed');
      },
      // 获取表格列是否排序
      getTableColumnSort(str){
          return this.getTableSomeValue(str, 'sort');
      },
      // 获取表格表头，列宽度，列固定，列排序的值
      getTableSomeValue(str, keyName){
        for (var value of this.tableHeaderArr) {
            if (value['name'] == str) {
                return value[keyName];
            }
        }
      }
    }
  }

</script>
